package com.contextor.magiccards.model.battle;

import com.contextor.magiccards.model.BaseEntity;
import com.contextor.magiccards.model.character.Personage;
import com.contextor.magiccards.model.user.User;

import javax.persistence.*;
import java.util.Date;

/**
 * User: Sergey
 * Date: 15.03.2011 21:58:26
 */
@Entity
@Table(name = "battles")
public class Battle extends BaseEntity {

    public static final int DEFAULT_MOVE_DURATION = 60;

    @Column(name = "date_created")
    private Date dateCreated;
    @Column(name = "max_move_duration")
    private int maxMoveDuration;

    @Column(name = "status")
    private BattleStatus status = BattleStatus.READY_TO_PLAY;

    @Column(name = "version")
    @Version
    private Integer version;

    @Column(name = "level")
    private Integer level;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "first_player_id")
    protected Personage firstPlayer;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "second_player_id")
    protected Personage secondPlayer;

    public Battle() {
    }

    public Battle(User user, Personage personage, int maxMoveDuration) {
        this.user = user;
        this.maxMoveDuration = maxMoveDuration;
        this.level = personage.getLevel();
        this.firstPlayer = personage;
        this.dateCreated = new Date();
    }

    public Integer getLevel() {
        return level;
    }

    public void setLevel(Integer level) {
        this.level = level;
    }

    public Date getDateCreated() {
        return dateCreated;
    }

    public void setDateCreated(Date dateCreated) {
        this.dateCreated = dateCreated;
    }

    public int getMaxMoveDuration() {
        return maxMoveDuration;
    }

    public void setMaxMoveDuration(int maxMoveDuration) {
        this.maxMoveDuration = maxMoveDuration;
    }

    public BattleStatus getStatus() {
        return status;
    }

    public void setStatus(BattleStatus status) {
        this.status = status;
    }

    public Integer getVersion() {
        return version;
    }

    public void setVersion(Integer version) {
        this.version = version;
    }

    public Personage getFirstPlayer() {
        return firstPlayer;
    }

    public void setFirstPlayer(Personage firstPlayer) {
        this.firstPlayer = firstPlayer;
    }

    public Personage getSecondPlayer() {
        return secondPlayer;
    }

    public void setSecondPlayer(Personage secondPlayer) {
        this.secondPlayer = secondPlayer;
    }
}
